package cn.thread;

import java.util.concurrent.*;

public class CallableTest implements Callable<Integer>{

    public static void main(String args[]) throws ExecutionException, InterruptedException {
        CallableTest c=new CallableTest();
        //参数是线程池中的线程数
        ExecutorService e = Executors.newFixedThreadPool(2);
        Future<Integer> f1 = e.submit(c);
        Future<Integer> f2 = e.submit(c);
         int s1=f1.get();
         int s2=f2.get();
         System.out.println(s1);
         System.out.println(s2);
         e.shutdown();
    }
    @Override
    public Integer call() throws Exception {
        int sun=0;
        for(int i=0;i<=100;i++){
            sun+=i;
        }
        return sun;
    }


}
